<?php

namespace App\Http\Forms;

use Illuminate\Support\Facades\DB;
use Kris\LaravelFormBuilder\Form;

class CategoryForm extends Form
{
    public function buildForm()
    {
//        $parent = [];
//        foreach (config('system.category') as $value) {
//            $parent[$value] = $value;
//        }
        $parent = DB::select('SELECT * FROM categories WHERE PID =0 AND DELETED_AT IS NULL  ORDER BY SORT DESC');
        $parent = array_column($parent, "name", "id");
//        array_unshift($parent,"顶级分类");
        $parent = [0 => "顶级分类"] + $parent;
        $this
            // ->add('pid', 'select', [
            //     'label' => '父级分类',
            //     'rules' => 'required|string',
            //     'choices' => $parent,
            // ])
            ->add('name', 'text', [
                'label' => "分类名称",
                'rules' => 'required|string',
            ])
            ->add('is_view_show', 'select', [
                'label' => "是否前台显示",
                'rules' => 'required|string',
                'choices' => [0 => "否", 1 => "是"],
            ])
            ->add('submit', 'submit', [
                'attr' => ['class' => "form-control btn btn-success"],
                'label' => '保存',
            ]);
    }
}
